<template>
	<view class="container">
		<view class="mainTitle">
			我的车辆
		</view>
		<scroll-view class="list" scroll-y="true" v-if='list.length>0'>
			<view class="box" v-for="(item, i) in list" :key='i' @click="selectCart(i)">
				<car-item :select='true' :isActive='selectIndex === i' :cartInfo="item"></car-item>
			</view>
			<view style="height: 160rpx;"></view>
		</scroll-view>
		<no-list tipInfo='暂无可选的车辆' v-else></no-list>
		<footer-button btnTip='添加车辆' @clickFooter='addCart'></footer-button>
	</view>
</template>
<script>
	import {myCart} from '@/untils/api.js'
	export default {
		data() {
			return {
				list:[],
				menuId:'',
				selectIndex: -1
			};
		},
		methods:{
			getMyCarts(){
			  const plan = this.$getStorageSync('selectPlanInfo') || '';
			  myCart().then((res) => {
				  this.list = res.data.filter((item) => {
					  if(plan){
						  return item.cartType == plan.cartType
					  }else{
						  return item
					  }
				  })
			  })
			},
			addCart(){
			   uni.navigateTo({
				   url:'/subpackage/mine/addCar'
			   })	
			},
			selectCart(i){
				this.selectIndex = i
				setTimeout(() => {
					// const plan = this.$getStorageSync('selectPlanInfo') || '';
					this.$setStorageSync('selectCartInfo', this.list[i])
					const seriveParams = this.$getStorageSync('seriveParams')
					seriveParams.cartId = this.list[i].id
					this.$setStorageSync('seriveParams', seriveParams)
					uni.navigateBack({
						delta:1,
					})
					// let url = '/subpackage/orderWashCar/index?cartId='+this.list[i].id
					// if(plan){
					//   url = url + '&menuId=' + plan.id
					// }
					// uni.redirectTo({
					// 	url
					// })
				}, 200)
			}
		},
		onShow() {
			this.getMyCarts()
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		height: 100%;
		background: #eee;
		overflow: hidden;
		.list{
			height: calc(100% - 160rpx);
		}
		.box{
			margin-bottom: 30rpx;
		}
	}

</style>
